/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.odhixon.volarme.persistence;

import org.garret.perst.IInputStream;
import org.garret.perst.IOutputStream;
import org.garret.perst.Index;
import org.garret.perst.Persistent;
import org.garret.perst.Storage;
import org.garret.perst.Types;

/**
 * Root.
 * @author Ariel Aguirre <odhixon@gmail.com>
 */
public class Root extends Persistent {

    private Index idxRegistros;
    private int proximoRegistroId;

    public Index getIdxRegistros() {
        return idxRegistros;
    }

    public void setIdxRegistros(Index idxRegistros) {
        this.idxRegistros = idxRegistros;
    }

    public int getProximoRegistroId() {
        return proximoRegistroId;
    }

    public void setProximoRegistroId(int proximoRegistroId) {
        this.proximoRegistroId = proximoRegistroId;
    }

    public Root() {
    }

    public Root(Storage storage) {
        super(storage);
        idxRegistros = storage.createIndex(Types.Int, true);
        proximoRegistroId = 1;
    }

    public void writeObject(IOutputStream out) {
        out.writeInt(proximoRegistroId);
        out.writeObject(idxRegistros);
    }

    public void readObject(IInputStream in) {
        proximoRegistroId = in.readInt();
        idxRegistros = (Index) in.readObject();
    }
}

